package com._9xcloud.leaverequest.service;

import com._9xcloud.leaverequest.domain.College;
import com._9xcloud.leaverequest.repository.CollegeRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by Administrator on 2015/5/28.
 */
@Repository
@Transactional
public class CollegeServiceImpl implements CollegeService {
    @Autowired
    private CollegeRepository collegeRepository;

    @Transactional(readOnly = true)
    public List<College> getAll() {
        return collegeRepository.findAll();
    }

    public void removeAll() {
        collegeRepository.deleteAll();
        collegeRepository.flush();
    }

    @Transactional(readOnly = true)
    public College getByName(String collegeName) {
        return collegeRepository.findByName(collegeName);
    }

    public College create(String collegeName) {
        College college = new College(collegeName);
        return collegeRepository.saveAndFlush(college);
    }
}
